<extend name="Public/base"/>

<block name="script">
<script>
	function check($obj,$k){
		var checked=$obj.checked;
		if(checked){
			$(".check"+$k).attr('checked',true);
		}else{
			$(".check"+$k).attr('checked',false);
		}
		home();
	}

	function checkChild($i){
		var  checkedLength=$('.check'+$i+':checked').length;
		if(checkedLength>0){
			$("#check"+$i).attr('checked',true);
		}else{
			$("#check"+$i).attr('checked',false);
		}
		home();
	}

	function home(){
		var home=$("#home").attr('checked');
		var  homeCheckedLength=$('[name="node_id[]"]:checked').length;
		if(homeCheckedLength>0){
			$("#home").attr('checked',true);
		}else{
			$("#home").attr('checked',false);
		}
	}
    iniAjaxFormDetail('#addAccessForm','__URL__/addAccess/groupId/<?php echo $_REQUEST["groupId"] ?>');

    $(".checkboxCtrl").change(function(){
        if($(this).prop("checked")==true){
            $(".list-group-item").find("input[type='checkbox']").prop("checked",true)
        }
        else {
                $(".list-group-item").find("input[type='checkbox']").prop("checked",false)
            }
    });
</script>
</block>
<block name="body">
    <style>
        li.list-group-item input {
            margin: 6px 2px;
            vertical-align: top;
        }
        #addAccessForm .list-group-item span {
            display:inline-block;
            width:112px;
            text-align: right;
            margin-right: 5px;
        }
        #addAccessForm .list-group-item label {
            display:inline-block;
            width:112px;
            text-align: right;
            margin-right: 5px;
        }
        .list-group-item {
            line-height: 22px;
        }
    </style>
    <div class="panel  panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">权限配置</h3>
        </div>
        <div class="panel-body">
            <form method="post" action="__URL__/insertAccess" class="pageForm required-validate" id="addAccessForm">
                <div class="box-body">
                <input type="hidden" name="role_id" value="{$Think.get.groupId}">
                <volist name="node" id="node1">
                    <ul class="list-group">
                        <li class="list-group-item">
                            <span class="text">{$node1.title}</span> <input type="checkbox" name="node_id[]" value="{$node1.id}_{$node1.level}_{$node1.pid}" <in name="node1.id"  value="$selectdNode[1]" >checked='checked'</in> class="checkboxCtrl" group="node_id[]" id="home" />
                        </li>
                        <volist name="node1._child" id="node2" key="k">
                            <li class="list-group-item">
                                <span class="text">{$node2.title}</span> <input type="checkbox" name="node_id[]" value="{$node2.id}_{$node2.level}_{$node2.pid}" <in name="node2.id"  value="$selectdNode[2]">checked='checked'</in> onclick="check(this,{$k})" id="check{$k}"/>
                                <volist name="node2._child" id="node3">
                                    <label>{$node3.title} <input type="checkbox" name="node_id[]" value="{$node3.id}_{$node3.level}_{$node3.pid}" <in name="node3.id"  value="$selectdNode[3]">checked='checked'</in> class="check{$k}" onclick="checkChild({$k})"/></label>
                                </volist>
                            </li>
                        </volist>
                    </ul>
                </volist>
                    <span style="margin-left:40px;">全选</span><input type="checkbox" class="checkboxCtrl" group="node_id[]" style="vertical-align:top;margin-left:10px;"/>
                </div>
                <div class="box-footer">
                    <div class="box-footer">
                        <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                </div>
            </form>
        </div>
    </div>


</block>
